<?php
defined('_JEXEC') or die('Restricted access'); 

jimport( 'joomla.html.html.tabs' );
JHtml::_('jquery.framework');
JHtml::_('behavior.keepalive');
JHTML::_('behavior.tooltip'); 
JHtml::_('behavior.framework');

?>

<script type="text/javascript">
	//<![CDATA[
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		if (pressbutton == 'save') {
			if (document.adminForm.name.value == ""){
				alert( 'Must have Distric name !' );
				document.adminForm.name.focus();
				return false;
			}
			if (document.adminForm.country_id.value == 0){
				alert( 'Please select a Country !' );
				document.adminForm.country_id.focus();
				return false;
			}
			if (document.adminForm.city_id.value == 0){
				alert( 'Please select a City !' );
				document.adminForm.city_id.focus();
				return false;
			}
			submitform( pressbutton );
		}
	}
	
</script>

<script type="text/javascript">
	//<![CDATA[
	var sectioncountrys = new Array;
	<?php
		foreach ($this->lists['countryToCity'] as $k=>$item) {
			echo "sectioncountrys[".$k."] = new Array( '$item->country_id','".addslashes( $item->id )."','".addslashes( $item->name )."' );\n\t\t";
		}
	?>

	function changeCity( listname, source, key, orig_key, orig_val ) {
		var list = eval( 'document.adminForm.' + listname );

		// empty the list
		for (i in list.options.length) {
			list.options[i] = null;
		}

		var i = 0;
		var j = 0;
		for (x in source) {
			if (source[x][0] == key) {
				opt = new Option();
				opt.value = source[x][1];

				opt.text = source[x][2];

				if ((orig_key == key && orig_val == opt.value) || i == 0) {
					opt.selected = true;
					j = opt.value;
				}
				list.options[i++] = opt;
			}
		}
		if(i == 0){
			opt = new Option();
			opt.value = 0;
			opt.text = '- Select City -';
			opt.selected = true;
			list.options[i++] = opt;
		}

		list.length = i;
	}
</script>

<form  id="adminForm"  action="<?php echo JRoute::_("index.php?option=com_wrd")?>" method="post" name="adminForm" >
	<div class="row-fluid">
	    <fieldset class="adminform">
	    	<legend><?php echo JText::_('Details')?></legend>
			<table class="table table-striped adminlist">
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('District Name')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->name; ?>" id="name" name="name" class="name"/> *
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Country')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['country']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('City')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['city']; ?>
					</td>
				</tr>
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Publish')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['published']; ?>
					</td>
				</tr>
            </table>
		</fieldset>
	</div>
	
	<input type="hidden" name="created_id" value="<?php echo $this->user->id;?>" />
	<input type="hidden" name="controller" value="distric" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="id" value="<?php echo (int)$this->data->id; ?>" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>